package com.wlc.rabbitmq.fanoutqueue;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author 王立朝
 * @description 广播模式-一个消息生产者对应多个消息订阅者
 * @date 2021-12-14 21:17:20
 */
@Component
public class FanoutProducer {

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void sendMessage() {
        for (int i = 0; i < 5; i++) {
            String message = "订阅模式消息" + i;
            System.out.println("我是生产信息的：" + message);
            rabbitTemplate.convertAndSend("fanoutExchange", "", message);
        }
    }

}
